<!--
 * @Author: liubei
 * @Date: 2021-08-03 10:45:58
 * @LastEditTime: 2021-09-07 10:46:44
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        (function () {
            try {
                throw new Error('这是一个错误');
            } catch (err) {
                console.log(err.name); // Error
                console.log(err.message); // 这是一个错误
                console.error(err); // error_demo.html:23 Error: 这是一个错误
                //    at error_demo.html:19
                //    at error_demo.html:25
            }
        });
    </script>

    <script>
        (function () {
            try {
                new Array(Infinity);
            } catch (err) {
                console.log(err.name); // RangeError
                console.log(err.message); // Invalid array length
                console.error(err); // RangeError: Invalid array length
                // at error_demo.html:35
                // at error_demo.html:41
            }

            try {
                1.223.toFixed(-1);
            } catch (err) {
                console.log(err.name); // RangeError
                console.log(err.message); // toFixed() digits argument must be between 0 and 100
            }

        });
    </script>

    <script>
        (function () {
            try {
                var a = b;
            } catch (err) {
                console.log(err.name); // ReferenceError
                console.log(err.message); // b is not defined
                console.error(err); // error_demo.html:61 ReferenceError: b is not defined
                // at error_demo.html:57
                // at error_demo.html:66
            }

        });
    </script>

    <script>
        (function () {
            try {
                // foo bar; // Uncaught SyntaxError: Unexpected identifier
            } catch (err) {
                console.log(err.name); // <未运行>
                console.log(err.message); // <未运行>
                console.error(err); // <未运行>
            }

            try {
                eval('foo bar');
            } catch (err) {
                console.log(err.name); // SyntaxError
                console.log(err.message); // Unexpected identifier
                console.error(err); // SyntaxError: Unexpected identifier
                // at error_demo.html:72
                // at error_demo.html:81
            }

            try {
                new Function('foo bar');
            } catch (err) {
                console.log(err.name); // SyntaxError
                console.log(err.message); // Unexpected identifier
                console.error(err); // SyntaxError: Unexpected identifier
                // at error_demo.html:72
                // at error_demo.html:81
            }

        });
    </script>

    <script>
        (function () {
            try {
                // null.toString();
                '1.'.toFixed(2);
            } catch (err) {
                console.log(err.name); // TypeError
                console.log(err.message); // "1.".toFixed is not a function
                console.error(err); // TypeError: "1.".toFixed is not a function
                // at error_demo.html:105
                // at error_demo.html:114
            }

        });
    </script>

    <script>
        (function () {
            try {
                decodeURIComponent('%')
            } catch (err) {
                console.log(err.name); // URIError
                console.log(err.message); // URI malformed
                console.error(err); // error_demo.html:125 URIError: URI malformed
                // at decodeURIComponent (<anonymous>)
                // at error_demo.html:121
                // at error_demo.html:130
            }

        });
    </script>

    <script>
        function throws() { throw '!' }
        let x = throws()
    </script>
    <script>
        console.log(typeof x)
    </script>
    <script>
        let x
    </script>

    <script>
        x = 1;
        x;
    </script>

</body>

</html>